<?php

namespace app\scm\controller;

use app\admin\common\Base;
use app\admin\common\Order;
use think\Db;
use app\admin\model\Order as Model;
use app\scm\model\PurchaseSalesList as PSLModel;

class Invpu extends Base
{
    public function index()
    {
        $data = $this->request->param();
        return (new Order) -> order_index($data,4); //所属类型 0，销售订单；1，销售单；2，退货单;3,购货订单，4，购货单，5，购货退货单  
    }

    public function add()
    {
        $data = $this->request->param();
        return (new Order) -> order_add($data,4);//订单类别;0,销售订单，1，销售单，2，销售退货单，3,购货订单，4，购货单，5，购货退货单
    }

    //编辑栏目1-1
    public function edit()
    {
        $data = $this->request->param();
        return (new Order) -> order_edit($data,4);//订单类别;0,销售订单，1，销售单，2，销售退货单，3,购货订单，4，购货单，5，购货退货单
    }

    // 添加购货单-更新
    public function save()
    {
        $data = $this->request->param();
        return (new Order) -> order_save($data,4);//订单类别;0,销售订单，1，销售单，2，销售退货单，3,购货订单，4，购货单，5，购货退货单
    }


        //审核与反审核
    public function shenhe($ids,$type)
    {
        $data = $this->request->param();
        return (new Order) -> order_shenhe($ids,$type,4);//订单类别;0,销售订单，1，销售单，2，销售退货单，3,购货订单，4，购货单，5，购货退货单
    }


    //对单与反撤销对单
    public function dd()
    {
        $data = $this->request->param();
        return (new Order) -> order_dd($data);
    }

    //编辑更新订单
    public function update()
    {
        $data = $this->request->param();
        return (new Order) -> order_update($data);
    }

    //删除
    public function del()
    {
        $data = $this->request->param();
        return (new Order) -> order_del($data);
    }


    // 采购费用
    public function purchase_cost()
    {
        $customer = Db::name('customer')->where(['is_del' => 0, 'enterprise_id' => $this->EnterpriseId])->where('is_customer', 'in', '1, 3')->select();
        $money_type = Db::name('money_type')->where(['is_del' => 0, 'enterprise_id' => $this->EnterpriseId])->select();

        $this->assign('customer', $customer);
        $this->assign('money_type', $money_type);
        return $this->fetch();
    }

    // 查询库存
    public function stock($store_id, $goods_id)
    {
        $data = $this->request->param();
        // $num = get_stock($data['store_id'], $data['goods_id']);
        $num = get_stock($store_id, $goods_id);
        return json(['status' => 1, 'msg' => '查询成功', 'info' => $num]);
    }
}
